package com.sike.netty.jinjie.channel.embeddedchannel;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;

import java.nio.charset.Charset;
import java.util.List;

public class ReplaceEncoder extends MessageToMessageEncoder<String> {
    private String target;

    private String replacement;

    public ReplaceEncoder(String target,String replacement) {
        this.target = target;
        this.replacement = replacement;
    }

    @Override
    protected void encode(ChannelHandlerContext ctx, String msg, List<Object> out) throws Exception {
        String encodeMessage = msg.replace(target,replacement);
        out.add(encodeMessage);
    }
}
